package net.maku.security.service;

import lombok.AllArgsConstructor;
import net.maku.framework.security.openid.OpenidUserDetailsService;
import net.maku.system.dao.SysUserDao;
import net.maku.system.entity.SysUserEntity;
import net.maku.wx.dao.WxUserDao;
import net.maku.wx.entity.WxUserEntity;
import net.maku.wx.service.WxUserDetailsService;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

/**
 * 小程序登录 OpenidUserDetailsServiceImpl
 *
 * @author 阿沐 babamu@126.com
 */
@Service
@AllArgsConstructor
public class OpenidUserDetailsServiceImpl implements OpenidUserDetailsService {
    private final WxUserDetailsService wxUserDetailsService;
    private final WxUserDao wxUserDao;

    @Override
    public UserDetails loadUserByOpenid(String openid) throws UsernameNotFoundException {
        WxUserEntity userEntity = wxUserDao.getByOpenid(openid);
        return wxUserDetailsService.getUserDetails(userEntity);
    }

}
